{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
	<h3 class="pb-3">律所管理</h3>
	{eq name="$id" value="0"}
	<table class="layui-table">
		<tr>
			<td class="layui-td-gray">律所名称<font>*</font>
			</td>
			<td>
				<input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="请输入部门名称"
					lay-reqText="请输入部门名称" class="layui-input">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">律所地址<font>*</font>
			</td>
			<td colspan="5">
				<div class="layui-form-item">
					<div class="layui-input-inline">
						<select name="provinceid" lay-filter="provinceid" lay-verify="required" lay-reqText="请选择省份">
							<option value="">请选择省份</option>
							<!-- 省份选项 -->
						</select>
					</div>

					<div class="layui-input-inline">
						<select name="cityid" lay-filter="cityid" lay-verify="required" lay-reqText="请选择城市">
							<option value="">请选择城市</option>
							<!-- 城市选项 -->
						</select>
					</div>

					<div class="layui-input-inline">
						<select name="distid" lay-filter="distid">
							<option value="">请选择区/县</option>
							<!-- 区/县选项 -->
						</select>
					</div>
				</div>
				<input type="text" name="address" autocomplete="off" lay-verify="required" lay-reqText="请输入详细地址"
					placeholder="请输入详细地址" class="layui-input">
			</td>
		</tr>
	</table>
	{else/}
	<table class="layui-table">
		<tr>
			<td class="layui-td-gray">律所名称<font>*</font>
			</td>
			<td>
				<input type="text" name="title" value="{$detail.title}" lay-verify="required" autocomplete="off"
					placeholder="请输入部门名称" lay-reqText="请输入部门名称" class="layui-input">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">律所地址<font>*</font>
			</td>
			<td colspan="5">
				<div class="layui-form-item">
					<div class="layui-input-inline">
						<select name="provinceid" lay-filter="provinceid" lay-verify="required" lay-reqText="请选择省份">
							<option value="">请选择省份</option>
							<!-- 省份选项 -->
						</select>
					</div>

					<div class="layui-input-inline">
						<select name="cityid" lay-filter="cityid" lay-verify="required" lay-reqText="请选择城市">
							<option value="">请选择城市</option>
							<!-- 城市选项 -->
						</select>
					</div>

					<div class="layui-input-inline">
						<select name="distid" lay-filter="distid">
							<option value="">请选择区/县</option>
							<!-- 区/县选项 -->
						</select>
					</div>
				</div>
				<input type="text" name="address" autocomplete="off" lay-verify="required" lay-reqText="请输入详细地址"
					placeholder="请输入详细地址" class="layui-input">
			</td>
		</tr>
	</table>
	{/eq}
	<div class="py-3">
		<input type="hidden" name="id" value="{$id}">
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool', 'oaTool'];
	function gouguInit() {
		var form = layui.form, tool = layui.tool;
		//监听提交
		form.on('submit(webform)', function (data) {
				let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					tool.sideClose(1000);
				}
			}
			tool.post("/lawyer/lawfirm/add", data.field, callback);
			return false;
		});

		var layer = layui.layer;

		// 加载省份选项
		$.get('/home/api/regionProvinces', function (data) {
			var redata = data.data;
			var html = '<option value="">请选择省份</option>';
			for (var i = 0; i < redata.length; i++) {
				html += '<option value="' + redata[i].id + '">' + redata[i].name + '</option>';
			}
			$('select[name="provinceid"]').html(html);
			form.render();
		});

		// 监听省份选择
		form.on('select(provinceid)', function (data) {
			var provinceId = data.value;
			if (provinceId) {
				// 加载城市选项
				$.get('/home/api/regionCitys', { provinceId: provinceId }, function (data) {
					var redata = data.data;
					var html = '<option value="">请选择城市</option>';
					for (var i = 0; i < redata.length; i++) {
						html += '<option value="' + redata[i].id + '">' + redata[i].name + '</option>';
					}
					$('select[name="cityid"]').html(html);
					form.render();
				});
			} else {
				$('select[name="cityid"]').html('<option value="">请选择城市</option>');
				$('select[name="distid"]').html('<option value="">请选择区/县</option>');
				form.render();
			}
		});

		// 监听城市选择
		form.on('select(cityid)', function (data) {
			var cityId = data.value;
			if (cityId) {
				// 加载区/县选项
				$.get('/home/api/regionDists', { cityId: cityId }, function (data) {
					var redata = data.data;
					var html = '<option value="">请选择区/县</option>';
					for (var i = 0; i < redata.length; i++) {
						html += '<option value="' + redata[i].id + '">' + redata[i].name + '</option>';
					}
					$('select[name="distid"]').html(html);
					form.render();
				});
			} else {
				$('select[name="distid"]').html('<option value="">请选择区/县</option>');
				form.render();
			}
		});
	}
</script>
{/block}
<!-- /脚本 -->